package kcg;

import static org.junit.Assert.assertTrue;
import kcg.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.events.BattleStartedEvent;
import robocode.control.snapshot.IRobotSnapshot;

/**
 * MikeTerry by Kelvin Green: Based on Wall sample Robot Walls - a sample robot by Mathew Nelson,
 * and maintained by Flemming N. Larsen
 * <p/>
 * Test to see if MikeTerry vists each corner.
 * 
 * @version 1.1
 * @author Kelvin Green
 */

public class TestMikeTerryCorners extends RobotTestBed {

  double height = 0;
  double width = 0;
  boolean leftWall = false;
  boolean rightWall = false;
  boolean topWall = false;
  boolean bottomWall = false;

  @Override
  public String getRobotNames() {
    return "sample.Fire,kcg.MikeTerry";
  }

  /**
   * This test runs for five rounds.
   * 
   * @return The number of rounds in this test
   */
  @Override
  public int getNumRounds() {
    return 5;
  }

  /**
   * After each turn, check to see if MikeTerry hits all four corners.
   * 
   * @param event Information about the current state of the battle
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    double x = robot.getX();
    double y = robot.getY();

    // Robot is close to the right wall.
    if (x > (width - 40)) {
      rightWall = true;
    }
    // Robot is close to the left wall.
    else if (x < 40) {
      leftWall = true;
    }
    // Robot is close to the bottom wall.
    else if (y > (height - 40)) {
      bottomWall = true;
    }
    // Robot is close to the top wall.
    else if (y < 40) {
      topWall = true;
    }

  }

  /**
   * Asserts that MikeTerry moved to all four corners during the battle.
   * 
   * @param event Details about the completed battle
   */
  @Override
  public void onBattleStarted(BattleStartedEvent event) {
    height = event.getBattleRules().getBattlefieldHeight();
    width = event.getBattleRules().getBattlefieldWidth();
  }

  /**
   * Asserts that MikeTerry moved to all four corners during the battle.
   * 
   * @param event Details about the completed battle
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue(rightWall & leftWall & topWall & bottomWall);
  }

}
